#ifndef MPU6500READ_H
#define MPU6500READ_H

#include "main.h"
#include "spi.h"
#include "mpu6500_reg.h"

#define MPU_HSPI hspi1
//样本数
#define NUM_SAMPLE 50
//片选
#define MPU_NSS_LOW HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4, GPIO_PIN_RESET);
#define MPU_NSS_HIGH HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4, GPIO_PIN_SET);

typedef struct _MPU_DATA
{
    //加速度
    float ax;
    float ay;
    float az;
    //角速度
    float gx;
    float gy;
    float gz;
    //角位移
    float Pitch;
    float Yaw;
    float Roll;
    //温度
    float temp;

    //陀螺仪误差校正
    float MPU6500_GYRO_X_OFFSET;
    float MPU6500_GYRO_Y_OFFSET;
    float MPU6500_GYRO_Z_OFFSET;
    //加速度计校正
    float MPU6500_ACCEL_X_OFFSET;
    float MPU6500_ACCEL_Y_OFFSET;
    float MPU6500_ACCEL_Z_OFFSET;

    //误差累积积分
    float exint;
    float eyint;
    float ezint;
    //四元数
    float q[4];

} Mpu6500_DataTydef;

uint8_t Mpu_Init(void);
/*IMU自检*/
void Mpu_Self_Test(void);
uint8_t mpu_write_byte(uint8_t const, uint8_t const);
uint8_t mpu_read_byte(uint8_t const);
void Get_MPU6500_Data(void);
float Get_16Bit_Data(uint8_t, uint8_t);

#endif
